import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pin_code_fields/pin_code_fields.dart';

import '../../app_main_portal.dart';



class CheckCodeComponent extends StatefulWidget {

  TextEditingController textCodeController;

  // const CheckCodeComponent({
  //   Key? key,
  //   required this.textCodeController,
  //   // required this.countdownTime,
  //   // required this.onPressed,
  // }) : super(key: key);
  CheckCodeComponent({
    Key? key,
    required this.textCodeController,
  }) : super(key: key);



  @override
  State<CheckCodeComponent> createState() => _CheckCodeComponentState();
}

class _CheckCodeComponentState extends State<CheckCodeComponent> {
  @override
  Widget build(BuildContext context) {
    return PinCodeTextField(
        length: 6,
        obscureText: false,
        animationType: AnimationType.fade,
        pinTheme: PinTheme(
          shape: PinCodeFieldShape.box,
          borderRadius: BorderRadius.circular(5),
          fieldHeight: 50,
          fieldWidth: 40,
          activeFillColor: Colors.white,
          inactiveFillColor: Colors.white,
        ),
        animationDuration: const Duration(milliseconds: 300),
        // backgroundColor: Colors.blue.shade50,
        enableActiveFill: true,
        autoFocus: true,
        autoUnfocus: true,
        controller: widget.textCodeController,
        keyboardType: TextInputType.number,
        onCompleted: (v) {
          debugPrint("Completed");
          // 请求后端验证验证码
          Navigator.push(context, CupertinoPageRoute(builder: (context) => AppMainPortal()));


        },
        onChanged: (value) {
          debugPrint(value);

        },
        beforeTextPaste: (text) {
          return true;
        },
        appContext: context,
      );
  }
}

